<?php


class ShopReportAction extends SecurityAction{
	function _initialize(){
        $this->assign("menuFirst",session('menuFirst')); 
        $this->assign("menuSecond",session('menuSecond')); 
    }
		
	function mlist(){		
		$ob = M("yq_order");
		$whereStr = "";
		$sql = array();

		if ($_GET['shopname']){
			$sql['c.shopname'] = array('like',"%{$_GET['shopname']}%");
			$whereStr .= " and c.shopname like '%{$_GET['shopname']}%' ";
		}
		
		if($_GET['stime'] && $_GET['etime']){
			$sql['yq_order.created_at'] = array(array('EGT',$_GET['stime']),array('ELT',$_GET['etime']),'AND');

			$whereStr .= " and yq_order.created_at >= '".$_GET['stime']. "' and yq_order.created_at <= '".$_GET['etime']."'";
		}

		$cpp = 20; //分页数
        import('ORG.Util.Page');// 导入分页类
/*        $count      = $ob->join(" yq_ordergoods b on yq_order.tid = b.order_id")
        				 ->join(" yq_shop c on yq_order.shopid = c.tid ")
        				 ->where($sql)
        				 ->group('yq_order.shopid, b.proid')->count();*/
        $sqlStr = 'SELECT COUNT(*) AS NUM from (SELECT COUNT(*) AS tp_count FROM yq_order LEFT JOIN 
 			yq_ordergoods b on yq_order.tid = b.order_id LEFT JOIN 
 			yq_shop c on yq_order.shopid = c.tid where 1=1 '; 
		$sqlStr .= $whereStr;
		$sqlStr .= ' GROUP BY yq_order.shopid, b.proid ) a';
 			
 		$count = M()->query($sqlStr);

        $Page       = new Page($count[0]['NUM'],$cpp);// 实例化分页类 传入总记录数和每页显示的记录数
        $show       = $Page->show();// 分页显示输出
        
		$list = $ob->join(" yq_ordergoods b on yq_order.tid = b.order_id")
				   ->join(" yq_shop c on yq_order.shopid = c.tid ")
				   ->field("yq_order.shopid, c.shopname,b.pname,sum(b.price) as  price,sum(b.discount_price)  as discount_price ")
				   ->where($sql)
				   ->group('yq_order.shopid, b.proid')
				   ->limit($Page->firstRow.','.$Page->listRows)->select();

		$this->assign("list", $list);
		$this->assign('show',$show);// 赋值分页输出

		$op = M('yq_shop');
		$shoplist = $op->where(array("is_forbit"=>"1"))->select();
		
		$this->assign('shoplist',$shoplist);
		$this->display("Report/mlist");
	}
	

}

?>